@extends("layouts.backend.webadmin")
@section('page-header')
<h1>
    <small>role\menu</small>
</h1>
@endsection
@section('content')
<!-- Main content -->
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-body">
                    @if($errors->any())
                    <ul class="alert alert-danger">
                        @foreach($errors->all() as $error)
                        <li>{{ $error }}</li>
                        @endforeach
                    </ul>
                    @endif
                        <form @if($action=='update')
                              action="{{route('admin.access.role.update')}}"
                              @else
                              action="{{route('admin.access.role.add')}}"
                              @endif
                              method="POST">
                            @if($action=='update')
                            <input type="hidden" name="id" value="{{$item->id}}" >
                            @endif

                            <div class="form-group">
                                <label for="name">名称</label>
                                <input id="name" type="text" name="name" @if($action=='update')value="{{$item->name}}"@endif >
                            </div>

                            @if($action=='update')
                            <div class="form-group">
                                <label for="sort">排序</label>
                                <input id="sort" type="text" name="sort" @if($action=='update')value="{{$item->sort}}"@endif >
                            </div>
                            @else
                            <input type="hidden" name="sort" value="0" >
                            @endif

                            <div class="form-group">
                                <label>授权</label>
                                @if (count($permissions)>0)
                                @foreach ($permissions as $perm)
                                @php
                                $code = explode('-',$perm['code']);
                                @endphp
                                @if(!isset($code[1]))
                                <br/>
                                <!--<input type="checkbox" name="permissions[]" value="{{$perm['id']}}" id="perm_{{$perm['id']}}">-->
                                <label for="perm_{{$perm['id']}}">{{$perm['name']}}</label>
                                <br/>
                                @else
                                <!--角色已有权限-->
                                <input type="checkbox" name="permissions[]" value="{{$perm['id']}}" id="perm_{{$perm['id']}}"

                                @if($action=='update')
                                    @foreach ($item->permissions as $hasPer)
                                        @if($hasPer->id==$perm['id'])
                                            checked
                                        @endif
                                    @endforeach
                                @endif
                                />
                                <label for="perm_{{$perm['id']}}">{{$perm['name']}}</label>
                                @endif
                                @endforeach
                                @else
                                <p>There are no available permissions.</p>
                                @endif
                            </div>
                            {!! csrf_field() !!}

                            <button type="submit" class="btn btn-primary">确认</button>
                        </form>
                </div>
            </div>
        </div>
    </div>
</section>
@stop